package com.guigu.qingcheng.orderservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.qingcheng.orderservice.mapper.TbReturnCauseMapper;
import com.guigu.qingcheng.orderservice.service.TbReturnCauseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.qingcheng.pojo.order.TbOrder;
import com.guigu.qingcheng.pojo.order.TbReturnCause;
import com.guigu.qingcheng.utils.R;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Service
public class TbReturnCauseServiceImpl extends ServiceImpl<TbReturnCauseMapper, TbReturnCause> implements TbReturnCauseService {

    @Override
    public R findPage(Integer page, Integer size, Map<String, Object> searchMap) {
        Page<TbReturnCause> tbReturnCausePage = new Page<>(page,size);

        QueryWrapper<TbReturnCause> wrapper = new QueryWrapper<>();
        if (searchMap != null) {
            if (searchMap.get("id") != null && !"".equals(searchMap.get("id")))
                wrapper.eq("id",searchMap.get("id"));
            if (searchMap.get("status") != null && !"".equals(searchMap.get("status")))
                wrapper.eq("status",searchMap.get("status"));
        }
        baseMapper.selectPage(tbReturnCausePage,wrapper);
        return R.ok().data("total",tbReturnCausePage.getTotal()).data("rows",tbReturnCausePage.getRecords());
    }

    @Override
    public R deletes(String ids) {
        List<TbOrder> list = new ArrayList<>();
        String[] split = ids.split(",");
        for(String str:split){
            int i = baseMapper.deleteById(Integer.parseInt(str));
        }
        return R.ok();
    }
}
